/*
 * PositionPage.fx
 *
 * Created on Feb 23, 2010, 8:33:42 PM
 */
package com.gpsbuddy.navigation;

import javafx.scene.Scene;
import com.gpsbuddy.graphics.zoomBarUI;
import com.gpsbuddy.graphics.zoomInUI;
import com.gpsbuddy.graphics.zoomOutUI;
import com.gpsbuddy.graphics.zoomSliderUI;
import com.gpsbuddy.main.Enviroment;
import javafx.scene.Group;
import javafx.animation.Interpolator;
import javafx.animation.KeyFrame;
import javafx.animation.Timeline;
import javafx.scene.shape.Circle;
import javafx.scene.paint.Color;
import com.gpsbuddy.objects.MapView;

/**
 * @author jonycus
 */
public class PositionPage extends Scene {

    public-init var env: Enviroment;
    public var multiplicator: Integer;
    var sceneHeight: Number = bind env.screenHeight;
    var sceneWidth: Number = bind env.screenWidth;
    var zoom = 13;
    var lon: Double = 21.452246;
    var lat: Double = 42.00381;
    def tiles = MapView {
            width: bind env.screenWidth;
            height: bind env.screenHeight;
            z: bind zoom with inverse;
            longitude: bind lon with inverse;
            lattitude: bind lat with inverse;
        };
    //TilesContainer {
      //          zoom: bind zoom with inverse;
        //        tilesMultip: bind multiplicator;
          //      lat: bind lat with inverse;
            //    lon: bind lon with inverse;
            //}
    var zBar = zoomBarUI {
                layoutX: 23;
                layoutY: sceneHeight / 2 - 82;
            }
    var zIn = zoomInUI {
                z: bind zoom with inverse;
                layoutX: 10;
                layoutY: sceneHeight / 2 - 120;
                map: tiles;
            }
    var zOut = zoomOutUI {
                z: bind zoom with inverse;
                layoutX: 10;
                layoutY: sceneHeight / 2 + 120;
                map: tiles;
            }
    var zSlider = zoomSliderUI {
                layoutX: 13;
                layoutY: sceneHeight / 2 + 105 - zoom * 10;
                z: bind zoom with inverse;
            }
    var mainNavigationBar = MainStatusBar {
                env: env;
                width: bind env.screenWidth;
                height: bind env.screenHeight;
                barHeight: 30
            }
    var point = Circle {
        radius: 7
        fill: Color.RED;
        opacity: 0.6;
        layoutX: sceneWidth/2
        layoutY: sceneHeight/2
    }

    var op: Number = 0;
    var lX: Number = -sceneWidth;
    var group = Group {
                layoutX: bind lX;
                opacity: bind op;
                content: [tiles, zIn, zOut, zBar, zSlider, mainNavigationBar, point]
            }

    postinit {
        tiles.calculateBounds ();
        content = [group];
    }

    public function transitIn() {
        Timeline {
            keyFrames: [
                KeyFrame {
                    time: 0s
                    values: [lX => -sceneWidth tween Interpolator.LINEAR, op => 0.0 tween Interpolator.LINEAR];
                }
                KeyFrame {
                    time: 0.5s
                    values: [lX => 0 tween Interpolator.LINEAR, op => 1.0 tween Interpolator.LINEAR];
                }
            ]
        }.play();
    }

}
